Skip to content

Phase 3: Command Layer Deduplication - #9

Merged
padak merged 1 commit into
mainfrom
phase-3-command-helpers
Feb 28, 2026
Merged

Phase 3: Command Layer Deduplication#9
padak merged 1 commit into
mainfrom
phase-3-command-helpers

Conversation

@padak

@padak padak commented Feb 28, 2026

Copy link
Copy Markdown
Member

Summary

  • Extract duplicated _get_formatter/_get_service from all 8 command files into shared commands/_helpers.py
  • Unify exit code mapping to consistent 3-case logic (INVALID_TOKEN->3, TIMEOUT/CONNECTION_ERROR/RETRY_EXHAUSTED->4, else->1)
  • Replace duplicated warning loops with shared emit_project_warnings helper

Acceptance Criteria

  • No _get_formatter / _get_service functions remain in individual command files
  • All command files import from commands._helpers
  • Exit code mapping consistent (3-case: INVALID_TOKEN->3, TIMEOUT/CONNECTION_ERROR/RETRY_EXHAUSTED->4, else->1)
  • Warning loop not duplicated -- all commands use emit_project_warnings
  • All existing CLI tests pass (472 passed)

Tests

  • All 472 existing tests pass
  • New: 6 tests in test_helpers.py for map_error_to_exit_code (invalid_token, timeout, connection, retry_exhausted, other, unknown)

Files Changed

  • NEW: src/keboola_agent_cli/commands/_helpers.py -- shared command helpers
  • NEW: tests/test_helpers.py -- unit tests for helpers
  • Modified: src/keboola_agent_cli/commands/project.py
  • Modified: src/keboola_agent_cli/commands/config.py
  • Modified: src/keboola_agent_cli/commands/job.py
  • Modified: src/keboola_agent_cli/commands/lineage.py
  • Modified: src/keboola_agent_cli/commands/org.py
  • Modified: src/keboola_agent_cli/commands/tool.py
  • Modified: src/keboola_agent_cli/commands/context.py
  • Modified: src/keboola_agent_cli/commands/doctor.py

Extract duplicated _get_formatter/_get_service, exit code mapping, and
warning loops from all 8 command files into commands/_helpers.py.
Unify exit code mapping to consistent 3-case logic across all commands.
@padak
padak merged commit 742fd4d into main Feb 28, 2026
@padak
padak deleted the phase-3-command-helpers branch February 28, 2026 00:21
martinsifra added a commit that referenced this pull request Aug 26, 2026
The big one (#2, upgraded): the diff sides' wire shape was WRONG in the
implementation and in the test fixtures that defined it. Verified against
connection (ConfigurationVersionResponse + ConfigurationDiffData OA
schemas, now recorded in the notes wire-truth table): each side is
{version, isDeleted, diff: {name, description, changeDescription,
isDisabled, configuration, rows}} -- content NESTED under diff,
version/deletion as side metadata. The classification and both take modes
now read the envelope; the flat-side code would have been dead on arrival
against the live API.

#1: resolve_conflict no longer takes branch_id -- it derives the branch
from the MR itself (branches.branchFromId), so the conflict-set guard and
the branch being written to can never disagree; a caller-supplied id could
point the REPLACing rebase at an unrelated dev branch the guard never
checked. A published/canceled MR (null branchFromId) is refused readably.

#3: take=theirs of a deleted side collapses to the delete resolution,
symmetric with ours ('production deleted it, dev changed it' is a live
conflict shape).
#4: deletion surfaces as top-level ours_deleted/theirs_deleted booleans on
get_config_diff (None = side never existed) -- it is side metadata, not a
content path.
#5: a 'both' row where the sides agree on the identical value carries
agreed: true -- agreement, not a conflict hotspot.
#2 (message half): a take side missing required envelope keys is reported
as a backend contract violation pointing at the resolved-body workaround,
not as caller error.
#6: wire ids compared via _same_id / int-coerced (find_merge_request_for_
branch, merge()'s was_active) -- a string-serialized branchFromId can no
longer silently defeat the post-merge cleanup.
#7: the feature pre-flight raises FeatureNotEnabledError carrying the new
ErrorCode.FEATURE_NOT_ENABLED (value matches the string SearchService
already emits; categorized 'configuration' like PAYG_NOT_AVAILABLE).
#8: ConfigError imported from ..errors like every other service; the
isDefault scan hoisted to services.base.find_default_branch_id and the
copies in config/sync/workspace services migrated (lib.py keeps its own
loop -- the SDK facade does not import the services layer); verify_token
is skipped when the server already serialized viewer (the polyfill's cost
dies with the polyfill); list --state validates against the closed
vocabulary instead of returning a silent count: 0 on a typo.
#9: test imports hoisted (no mid-file noqa), mocks spec'd at the L3 seam
(KeboolaClient + MergeRequests -- a renamed L3 method now fails the tests),
and regression tests added for every finding (82 tests total).

Doc drift: layer2/layer3 references updated to BRANCHES_MERGE_REQUESTS_
FEATURE, the layer3 open nit closed, tokens.py line ref fixed.

Review: tasks/pr-703-review.md (2026-08-27).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant